using System;
using System.Windows.Forms;
using FridayShopping.DataModel;

namespace FridayShopping.UI
{
	/// <summary>
	/// Summary description for CategoryProperties.
	/// </summary>
	public class CategoryPropertiesForm : System.Windows.Forms.Form, IItemPropertiesForm
	{
		private Category category;
		private System.Windows.Forms.Label lbl_Name;
		private System.Windows.Forms.TextBox edit_Name;
		private System.Windows.Forms.Button btn_Cancel;
		private Microsoft.WindowsCE.Forms.InputPanel inputPanel1;
		private System.Windows.Forms.MainMenu mainMenu1;
	
		public CategoryPropertiesForm(Category category)
		{
			this.category = category;
			InitializeComponent();
		}

		public CategoryPropertiesForm()
		{
			InitializeComponent();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(CategoryPropertiesForm));
			this.lbl_Name = new System.Windows.Forms.Label();
			this.edit_Name = new System.Windows.Forms.TextBox();
			this.btn_Cancel = new System.Windows.Forms.Button();
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.inputPanel1 = new Microsoft.WindowsCE.Forms.InputPanel();
			// 
			// lbl_Name
			// 
			this.lbl_Name.Enabled = ((bool)(resources.GetObject("lbl_Name.Enabled")));
			this.lbl_Name.Font = ((System.Drawing.Font)(resources.GetObject("lbl_Name.Font")));
			this.lbl_Name.Location = ((System.Drawing.Point)(resources.GetObject("lbl_Name.Location")));
			this.lbl_Name.Size = ((System.Drawing.Size)(resources.GetObject("lbl_Name.Size")));
			this.lbl_Name.Text = resources.GetString("lbl_Name.Text");
			this.lbl_Name.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("lbl_Name.TextAlign")));
			this.lbl_Name.Visible = ((bool)(resources.GetObject("lbl_Name.Visible")));
			// 
			// edit_Name
			// 
			this.edit_Name.Enabled = ((bool)(resources.GetObject("edit_Name.Enabled")));
			this.edit_Name.Font = ((System.Drawing.Font)(resources.GetObject("edit_Name.Font")));
			this.edit_Name.Location = ((System.Drawing.Point)(resources.GetObject("edit_Name.Location")));
			this.edit_Name.MaxLength = ((int)(resources.GetObject("edit_Name.MaxLength")));
			this.edit_Name.Multiline = ((bool)(resources.GetObject("edit_Name.Multiline")));
			this.edit_Name.PasswordChar = ((char)(resources.GetObject("edit_Name.PasswordChar")));
			this.edit_Name.ScrollBars = ((System.Windows.Forms.ScrollBars)(resources.GetObject("edit_Name.ScrollBars")));
			this.edit_Name.Size = ((System.Drawing.Size)(resources.GetObject("edit_Name.Size")));
			this.edit_Name.Text = resources.GetString("edit_Name.Text");
			this.edit_Name.TextAlign = ((System.Windows.Forms.HorizontalAlignment)(resources.GetObject("edit_Name.TextAlign")));
			this.edit_Name.Visible = ((bool)(resources.GetObject("edit_Name.Visible")));
			this.edit_Name.WordWrap = ((bool)(resources.GetObject("edit_Name.WordWrap")));
			this.edit_Name.GotFocus += new System.EventHandler(this.edit_Name_GotFocus);
			// 
			// btn_Cancel
			// 
			this.btn_Cancel.Enabled = ((bool)(resources.GetObject("btn_Cancel.Enabled")));
			this.btn_Cancel.Font = ((System.Drawing.Font)(resources.GetObject("btn_Cancel.Font")));
			this.btn_Cancel.Location = ((System.Drawing.Point)(resources.GetObject("btn_Cancel.Location")));
			this.btn_Cancel.Size = ((System.Drawing.Size)(resources.GetObject("btn_Cancel.Size")));
			this.btn_Cancel.Text = resources.GetString("btn_Cancel.Text");
			this.btn_Cancel.Visible = ((bool)(resources.GetObject("btn_Cancel.Visible")));
			this.btn_Cancel.Click += new System.EventHandler(this.btn_Cancel_Click);
			// 
			// CategoryPropertiesForm
			// 
			this.ClientSize = ((System.Drawing.Size)(resources.GetObject("$this.ClientSize")));
			this.Controls.Add(this.btn_Cancel);
			this.Controls.Add(this.edit_Name);
			this.Controls.Add(this.lbl_Name);
			this.Enabled = ((bool)(resources.GetObject("$this.Enabled")));
			this.Font = ((System.Drawing.Font)(resources.GetObject("$this.Font")));
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Location = ((System.Drawing.Point)(resources.GetObject("$this.Location")));
			this.Menu = this.mainMenu1;
			this.Text = resources.GetString("$this.Text");
			this.Visible = ((bool)(resources.GetObject("$this.Visible")));
			this.Closing += new System.ComponentModel.CancelEventHandler(this.CategoryPropertiesForm_Closing);
			this.Load += new System.EventHandler(this.CategoryPropertiesForm_Load);

		}
		#endregion

		#region IItemPropertiesForm Members

		public ItemBase GetItem(EditMode mode)
		{
			if (mode == EditMode.Add &&  category == null) 
			{
				category = new Category();
			} 
			category.Name = edit_Name.Text;

			return category;
		}

		public void SetDefaultValue(object obj)
		{
		}
		#endregion

		#region Form Event Handlers
		private void CategoryPropertiesForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			if (this.DialogResult != DialogResult.Cancel) 
			{
				string name = edit_Name.Text;
				if (name.Trim().Length == 0) 
				{
					MessageBox.Show(LangResources.Instance.Resources.GetString("emptyCategoryName"), 
						LangResources.Instance.Resources.GetString("applName"));
					e.Cancel = true;
				}
			}
			inputPanel1.Enabled = false;
		}

		private void btn_Cancel_Click(object sender, System.EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
		}

		private void CategoryPropertiesForm_Load(object sender, System.EventArgs e)
		{
			if (category != null) 
			{
				edit_Name.Text = category.Name;
			}
		}

		private void edit_Name_GotFocus(object sender, System.EventArgs e)
		{
			inputPanel1.Enabled = true;
		}
		#endregion

	}
}
